#include "svr.h"

ORAPROC *dbconns;

int svr_init(char *passwd)
{/*{{{*/
    char buf[200];
    int res;

    oraproc_init();
    ALLOC_MULTI_DOERR(dbconns, ORAPROC, cnfg_info.start,
            sprintf(buf, "%s: alloc dbconns fail", SERVER_NAME);
            fprintf(stderr, "%s\n", buf); errlog(buf);
            return(-1);
            );
    int thrd_idx;     
    for(thrd_idx=0; thrd_idx<cnfg_info.start; ++thrd_idx)
    {   
        res=oraproc_connect_ex(
                cnfg_info._db_.user,
                passwd,
                cnfg_info._db_.host,
                &dbconns[thrd_idx]);
        if(res != ORA_OK)
        {
            sprintf(buf, "%s: thrd(%d) connect to db fail, res:%d",
                    SERVER_NAME, thrd_idx, res);
            fprintf(stderr, "%s\n", buf); errlog(buf);
            return(-1);
        }
    }

    return(0);
}/*}}}*/

int svr_done()
{/*{{{*/
    int res;

    int thrd_idx;
    for(thrd_idx=0; thrd_idx<cnfg_info.start; ++thrd_idx)
    {   
        res=oraproc_disconnect_ex(dbconns[thrd_idx]);
        if(res != ORA_OK)
        {
            errlog("%s: thrd(%d) disconnect from db fail, res:%d",
                    SERVER_NAME, thrd_idx, res);
        }
    }
    return(0);
}/*}}}*/
